<template>
	<view class="content pc-tou-gao-64">
		<Dzhifu
		:show="show"
		:payType="payType"
		:jine="jine"
		@close="show = false"
		@uidapi="getUid_api"

		></Dzhifu>
			<view class="d-kuan-juzhong  d-beijing-hui3">
			<!--头部-->
    	    <view class="d-kuan pc-dingbu">
    	        <DToubu ref="dToubu" 
				@login-success="handleLoginSuccess"
				@clear-audio="clearAllAudio" 
				@logout-success="handleLogout"
				:dengluxianshi="denglu_xianshi"
				@update-dengluxianshi="handleUpdateDengluxianshi"
				></DToubu>
    	    </view>
		
			<!--头部-->
			<!--下面内容-->
			<view class="d-kuan d-clear" >
				<uv-row customStyle="margin-bottom: 10px" :gutter="10">
					<uv-col span="2" class="pc-yincang">
						<!--左边导航-->
						<view class="d-daohang d-you-10 d-shang-20" id="zuo-daohang " :style="{height: leftNavHeight}">
							<view class="d-daohang-5">
								<Ddaohang  @denglu-fabu="denglu_fabu"></Ddaohang>
							</view>
						</view>
						<!--左边导航-->
					</uv-col>
					<uv-col :span="kuan_shu">
						<view class="d-guding-1">
							<uv-navbar leftText="返回" :fixed="false" title="应用详情" :safeAreaInsetTop="false" customStyle="border-radius: 20rpx;" bgColor="#f3f3f3">
								<template v-slot:left >
									<view class="uv-nav-slot" @click="fanhui">
										<uv-icon name="arrow-left" size="19" ></uv-icon>
										<!--uv-line direction="column" :hairline="false" length="16" margin="0 8px"></uv-line-->
										<!--uv-icon name="home" size="20"></uv-icon-->
									</view>
								</template>
							</uv-navbar>
						</view>
						<view class="pc-neikuang-20" >
							
							<!---->
							<view class="beijing-2 d-kuan d-buhuanhang d-xia-20 d-piaofu-0">
								<!--图片-->
								<view class="d-zuo d-tu-kuan-420 d-piaofu-0" >
									<view v-if="zhishi_data.jiage == 0" class="d-piaofu-1">免费</view>
									<view v-else class="d-piaofu-1">付费</view>
									
									<image :src="zhishi_data.tubiao" 
									style="width: 100%; height: 100%;"
									radius="10"  
									mode="aspectFit"
									></image>
								</view>
								<view class="d-kuan d-neikuang-10">
									<view class="d-chaochu-1 d-jiacu">{{ zhishi_data.title }}</view>
									<view class="d-chaochu-2 d-ziti-14 d-wenzi-yanse-hui d-shang-10">
										{{ zhishi_data.jianjie }}
									</view>
									<view class="d-chaochu-2 d-ziti-14 d-wenzi-yanse-hui d-shangxia-5 d-shangxia-30">
										<uv-icon name="arrow-right" color="#a7a7a7" labelColor="#a7a7a7" size="12" :label="zhishi_data.lanmu_name"></uv-icon>
										
									</view>
									
									<view class="d-goumai d-piaofu-2 ">   
										<uv-icon class="d-juzhong" name="red-packet" color="#47e0ca" size="28" :label="zhishi_data.jiage +'元'" labelColor="#ff681d"></uv-icon> 
										<uv-button  v-if="zhishi_data.goumai == 0" size="small" type="warning" custom-style="borderRadius: 40rpx"  @click="goumai"> 购 买 </uv-button>
										<uv-button v-else type="error" size="small" :plain="true" custom-style="borderRadius: 40rpx"  > 已购买 </uv-button>
									    
									</view>
								</view>
							</view>
							<view v-if="zhishi_data.zengsonge > 0" class="d-kuan d-clear d-xia-10">
								<uv-alert :title="'赠送赞助金：'+zhishi_data.zengsonge+'元'" 
									type="error" 
									:description="'购买《'+zhishi_data.title+'》即可赠送 '+zhishi_data.zengsonge+' 元赞助金。赞助金可以购买：模板，插件, 问答'">
								</uv-alert>
							</view>
							<view v-if="zhishi_data.chuangyejin > 0" class="d-kuan d-beijing-bai d-yuanjiao-10 d-xia-10">
								<view class="d-bianhua-10 ">
									<text class="d-zuo">赞助金：{{ zhishi_data.chuangyejin }} 元</text>
									<text v-if="zhishi_data.goumai == 0"  class="d-you" @click="chuangyejin_post(zhishi_data.id)">赞助购买</text>
									<text v-else  class="d-you">已购买</text>
									<view class="d-clear"></view>
								</view>
								
							</view>
							<!--充值-->
							<view v-if="uid" class="d-kuan d-clear d-xia-10">
								<text class="d-zuo">赞助金：{{ uid_data.score }}</text>
								<view class="d-you">
									
									<text class="d-zuo">余额：{{ uid_data.money }}</text>
									<uv-icon @click="show = true" name="red-packet" label="充值 " class="d-zuo-10 d-you"></uv-icon>
								</view>

							</view>
							<view class="d-kuan d-clear d-shang-20"></view>
							
							
							<uv-tabs :list="list" @click="neirong_id" lineWidth="30" lineColor="#4addc7"></uv-tabs>
    	                    <view class="d-kuan" v-if="neirong_id_data == 1">
    	                        <view class="d-kuan d-shangxia-30 d-beijing-huise d-yuanjiao-10">
    	                            <view class="d-neikuang-10">
    	                                <view class="d-jiacu d-wenzi-20">购买必知</view>
    	                                <view class="d-shangxia-5">1.《{{ zhishi_data.title }}》为“对信系统应用”。</view>
    	                                <view class="d-shangxia-5">2.本产品为付费应用，共{{ zhishi_data.jiage }}元，购买成功后，即可永久性使用该产品所有内容。</view>
    	                                <view class="d-shangxia-5">3.本产品为虚拟内容服务，一经购买成功，概不退款，请你理解。</view>
									
    	                            </view>
									<view class="d-neikuang-10">
    	                                <view class="d-jiacu d-wenzi-20">下载方法</view>
    	                                <view class="d-shangxia-5">1.登录你网站的后台。</view>
    	                                <view class="d-shangxia-5">2.首页 -> 应用市场 ，找到应用后，点击下载，安装即可。</view>
    	                               
									
    	                            </view>
								
    	                        </view>
    	                        
    	                    </view>
							<view class="d-kuan" >
    	                        <view class="d-jiacu d-wenzi-20 d-xia-10">详情</view>
    	                        <uv-cell-group>
								
		                        	
    	                            <uv-cell v-for="(tie,index) in tiezi_list" span="12" icon="arrow-right" title="版本更新" value="阅读" right-icon="play-circle" :isLink="true" customStyle="border-bottom: none;">
    	                                <template v-slot:title>
											<text class="d-wenzi-yanse-hongse" v-if="tie.moshi == 0 && zhishi_data.jiage > 0">试读</text>
				                        	<text @click="yuedu_data(tie.id,id)">{{ tie.title }}</text>
				                        </template>
    	                                <template v-slot:value>
											<uv-icon  @click="ke_data(tie.id,id)" name="file-text" label="阅读"></uv-icon>
				                        </template>
										<template v-slot:right-icon>
											<text  @click="yuedu_data(tie.id,id)" class="d-zuo-10 d-you-10">听讲</text>
											<uv-icon   @click="yuedu_data(tie.id,id)" size="30rpx" name="play-circle"></uv-icon>
										</template>
    	                            </uv-cell>
									<!-- 加载状态提示 -->
									<view class="d-kuan d-juzhong d-shangxia-20" v-if="isLoading">
										<uv-loading-icon></uv-loading-icon>
									</view>
									<view class="d-kuan d-juzhong d-shangxia-20 d-wenzi-hui" v-if="noMoreData">
										<uv-divider text="没有更多数据了"></uv-divider>
											<uv-gap height="100" bgColor="#bbb"></uv-gap>
									</view>
		                        </uv-cell-group>

    	                    </view>
							<!--介绍-->
							<view class="d-kuan d-shangxia-20 uv-content">
								<uv-parse :content="zhishi_data.neirong_data"></uv-parse>
							</view>
						    <!--介绍-->
						</view>
						
					</uv-col>
					<uv-col span="4" class="pc-yincang">
						<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight,width: zhongjianWidth}">
							
								<!--view class="d-kuan" id="yuedu_gao" :style="{height: leftNavHeight,marginTop: '10px'}">
									<view class=" gundong-2"  style="height: 100%; display: flex; flex-direction: column;overflow-y: auto;">
										<view class="d-yuanjiao-10  d-beijing-e3 d-neikuang-15 ">
											
										</view>
									</view>
								</view-->
							
						</view>
					</uv-col>
				</uv-row>
				
				

			</view>
	
		</view>


	</view>

</template>

<script>
	import Api from '@/utils/api.js';
	import ZhishiApi from '@/utils/zhishi_api.js';
	import YingyongApi from '@/utils/yingyong_api.js';
	import { getRequest,postRequest } from '@/utils/wxRequest.js';
    import DToubu from '@/components/d-toubu/d-toubu.vue';
	import NlAudioPlayer from '@/uni_modules/nl-audio-player/components/nl-audio-player/nl-audio-player.vue';
	import HbComment from '@/uni_modules/hb-comment/components/hb-comment/hb-comment.vue'; // 添加这行
	import Ddaohang from '@/components/d-daohang/d-daohang.vue';
	import Dzhifu from '@/components/d-zhifu/d-zhifu.vue';
	export default {
		data() {
			return {
				title: 'Hello',
				leftNavHeight: '500rpx', // 默认高度
				leftNavHeight_neirong:'600rpx',// 默认高度
                rightColWidth: '70%', // 默认宽度
				zhongjianWidth: '20%', // 默认宽度
				daohang: [
					{
						id:'1',
						name: '首页', 
						icon: 'home',

					},
					{
						id:'2',
						name: '心理学', 
						icon: 'home',
						erji: [	
							{id: '2-1', name: '情绪管理'},
					    	{id: '2-2', name: '心理疗愈'},
					    	{id: '2-3', name: '行为心理学'}
						]
					},
					
				],
                list: [
                    {
                        id: '1',
                        name: '应用介绍',
                        title: 'tab1',
                        content: 'tab1内容',
                    }
                ],
                neirong_id_data:1,
				erjidata:[],
				erjiindex:'',//当前激活的二级菜单索引
				activeIndex: -1, // 当前激活的一级菜单索引
                baseList:[
                    {
                        name: 'question-circle',
                        title: '试读',
                        yidu:1,
                        kedu:2,
                        gengxin:1,
                    },
                    {
                        name: 'play-circle',
                        title: '已经更新',
                        gengxin:1,
                    },
                    {
                        name: 'share',
                        title: '已经学习',
                        gengxin:1,
                    },
                    {
                        name: 'share',
                        title: '分享'
                    }

                ],
				content: `
                    <p>这是一个段落。</p>
                    <p>这是另一个段落。</p>
                `,
                yuedu:false,
				audioUrl:'/static/mp3/mp3.mp3',
				pinglunzxianshi:0,
				commentData: {
					readNumer: 193,
    				comment: [
    				],
				},
				like_1: false, // 确保所有模板中用到的属性都已定义
				tiwenneirong:'',
				rightColLeft: '0px', // 添加这个属性
				denglu_xianshi:0, // 登录显示
				zhishi_data:{},
				tiezi_list:[],
				currentPage: 1, //下拉加载
    			pageSize: 12, //下拉加载
    			isLoading: false, //下拉加载
    			noMoreData: false, //下拉加载
				ke:[],
				kuan_shu:7, // 7个
				uid_data:[], // 用户信息
				show: false, // 控制组件显示/隐藏
				payType: 'weixin', // 支付类型
				title: '充值', // 支付标题
				jine:0, // 充值金额
				

			}
		},
        components: {
          DToubu,
		  NlAudioPlayer,
		  HbComment, // 添加这行
		  Ddaohang,
		  Dzhifu,
        },
		mounted() {
			
    	    this.setLeftNavHeight();
            this.getRightColWidth(); // 添加这行
    	    // 添加窗口大小变化监听
    	    window.addEventListener('resize', this.setLeftNavHeight);
            window.addEventListener('resize', this.getRightColWidth); // 添加窗口大小变化监听
    	},
    	beforeDestroy() {
    	    // 移除监听
    	    window.removeEventListener('resize', this.setLeftNavHeight);
            window.removeEventListener('resize', this.getRightColWidth); // 添加这行
			this.clearAllAudio();
    	},
		onShow() {
			
			var e = this;
			
			this.getUid_api();
			this.getxiangqing_api();
		},
		onLoad(e) {
			this.id = e.id;
		},
		computed: {
		  	yidenglu() {
		  	  return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
		  	},
			uid: {
		  	  get() {
		  	    return this.$store.state.memberuid;
		  	  },
		  	  set(value) {
		  	    // 当代码尝试设置uid时，不报错而是打印警告
		  	    console.warn('尝试修改只读的uid计算属性，应该通过store修改memberuid');
		  	    // 可选：如果需要支持修改，可以添加store.commit来更新状态
		  	    // this.$store.commit('setMemberUid', value);
		  	  }
		  	},
		  	touxiang() {
		  	  return this.$store.state.member? this.$store.state.member.avatar : '';
		  	},
		  	name1() {
		  	  return this.$store.state.member? this.$store.state.member.name : '';
		  	}
		},

		onUnload() {
  		  this.clearAllAudio();
  		},
		methods: {
			// ...其他方法保持不变...
			yiji(index) {
    		  // 切换激活的一级菜单
    		  this.activeIndex = index;
    		  // 根据激活的一级菜单显示对应的二级菜单
    		  this.erjidata = this.daohang[index].erji;
			  console.log(this.erjidata);
    		},
			erji(index) {
    		  // 切换激活的二级菜单
    		  this.erjiindex = index;
    		},
			toggleErji(index) {
    		  if (this.activeIndex === index) {
    		    // 点击已激活的菜单，收起二级菜单
    		    this.activeIndex = -1;
    		    this.currentErji = [];
    		  } else {
    		    // 点击新的菜单，显示对应的二级菜单
    		    this.activeIndex = index;
    		    this.currentErji = this.daohang[index].erji;
    		  }
    		},
			setLeftNavHeight() {
        	    // 获取系统信息
        	    const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowHeight;
        	    const headerHeight = 60; // 头部高度估计值
        	    const calculatedHeight = windowHeight - headerHeight;
				
        	    // 设置左边导航高度
        	    this.leftNavHeight = `${calculatedHeight}px`;

				const headerHeight_neirong = 120; // 头部高度估计值
        	    const calculatedHeight_neirong = windowHeight - headerHeight_neirong;

				this.leftNavHeight_neirong = `${calculatedHeight_neirong}px`;
        	},
            // ...其他方法...
             getRightColWidth() {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowWidth = systemInfo.windowWidth;
				var d = this;
               this.$nextTick(() => {
				if(windowWidth >=920){
					//d.gao = 20;
					d.kuan_shu = 7;
					//d.swiperHeight = '250';
				} else {
					//d.gao = 10;
					d.kuan_shu = 12;
					//d.swiperHeight = '120';

				}
                 const query = uni.createSelectorQuery().in(this);
                 query.select('#youbiankuan').boundingClientRect(rect => {
                   if (rect) {
                     /*this.rightColWidth = `${rect.width+20}px`;
                     console.log('右侧列宽度:', this.rightColWidth);*/
					 	this.rightColWidth = `${rect.width}px`;
                    	this.rightColLeft = `${rect.left}px`; // 计算左侧位置
                    	console.log('右侧列位置:', this.rightColLeft);
                   }
                 }).exec();
               });
             },
            // 返回
            fanhui() {
				// 先清理音频
				this.clearAllAudio();
               // 获取页面栈
                 const pages = getCurrentPages();
                 // 如果页面栈长度小于等于1，说明没有上一级页面
                 if (pages.length <= 1) {
                    console.log('没有上一级页面');
                    uni.reLaunch({
                      url: '/pages/index/index'
                    });
                 } else {
                    // 有上一级页面则返回
                    uni.navigateBack({
                      delta: 1
                    });
                }
            },
			handleLoginSuccess() {
  			  this.$forceUpdate();
			  this.getUid_api();
  			},
            neirong_id(e){
                this.neirong_id_data = e.id;
                console.log(e.id);
            },
            tiwen(e){
				if (!this.denglu_jiance()) return;
                console.log('tiwen',e);
                this.yuedu = true;
            },
			ke_data(id,cid){
				if (!this.denglu_jiance()) return false; // 明确返回 false
				console.log('ke',id);
				try {
  				  uni.navigateTo({
  				    url: '/pages/ke/ke?id='+id+'&cid='+cid,
  				    fail: (err) => {
  				      console.error('跳转失败:', err)
  				    }
  				  })
  				} catch (e) {
  				  console.error('跳转异常:', e)
  				}
				//this.yuedu = true;
				
				//return true; // 执行成功返回 true
			},
            yuedu_data(e){
				if(this.$refs.audioPlayer && this.$refs.audioPlayer.length) {
    			  this.$refs.audioPlayer.forEach(player => {
    			    const audioCtx = player.getAudioContext();
    			    if (audioCtx) {
    			      audioCtx.stop();
    			      audioCtx.destroy();
    			    }
    			  });
    			}
				this.ke.yinpin = '';
				if (!this.denglu_jiance()) return false; // 明确返回 false
 				 console.log('yudu0000000000000',e);
 				 this.yuedu = true;
				
 				 return true; // 执行成功返回 true
            },
            guanbi(){
                this.yuedu = false;
				if(this.$refs.audioPlayer && this.$refs.audioPlayer.length) {
    			  this.$refs.audioPlayer.forEach(player => {
    			    const audioCtx = player.getAudioContext();
    			    if (audioCtx) {
    			      audioCtx.stop();
    			      audioCtx.destroy();
    			    }
    			  });
    			}
            },
			// 关闭播放音频
			clearAllAudio() {
    		  if(this.$refs.audioPlayer && this.$refs.audioPlayer.length) {
    			  this.$refs.audioPlayer.forEach(player => {
    			    const audioCtx = player.getAudioContext();
    			    if (audioCtx) {
    			      audioCtx.stop();
    			      audioCtx.destroy();
    			    }
    			  });
    			}
    		},
			add(e) {
    		  console.log('add', e);
    		  // 这里可以添加评论逻辑
    		},
    		del(e) {
    		  console.log('del', e);
    		  // 这里可以删除评论逻辑
    		},
    		like(e) {
    		  console.log('like', e);
    		},
			focusOn(e) {
    		  console.log('focusOn', e);
    		},
			tiwenzhi(){

                this.pinglunzxianshi = this.pinglunzxianshi === 1 ? 0 : 1;
				if(this.pinglunzxianshi === 1) {
                    this.$nextTick(() => {
                        setTimeout(() => {
                            const textarea = this.$refs.commentTextarea?.$el?.querySelector('textarea');
                            if(textarea) {
                                textarea.focus();
                                // 将光标移动到文本末尾
                                const length = textarea.value.length;
                                textarea.setSelectionRange(length, length);
                            }
                        }, 100);
                    });
                }
                
				console.log('pinglun',this.pinglunzxianshi);
            },
			// ... existing methods ...
			handleBlankClick(e) {
				const isCommentArea = e.target.closest('.d-pinglun-2') || 
			                        e.target.closest('.d-tijiao-0') ||
			                        e.target.closest('.uv-search') ||
			                        e.target.closest('.uv-textarea');
			
			    // 如果点击的是非评论区域且评论框是显示状态，则关闭评论框
			    if(!isCommentArea && this.pinglunzxianshi === 1) {
			        this.pinglunzxianshi = 0;
			    }
    		},
			handleTextareaBlur() {
    		    //this.pinglunzxianshi = 0;
				setTimeout(() => {
    			    this.pinglunzxianshi = 0;
    			}, 300);
    		},
			//提交问答
			tijiao_wenda(){
				if (!this.denglu_jiance()) return;
			    console.log('提交问答');
			    //this.pinglunzxianshi = 0;
			    // 这里可以添加提交问答的逻辑
				//显示提交成功
				uni.showToast({
				  title: '提交成功',
				  icon: 'success',
				  duration: 2000
				});
				//清空输入框
				this.tiwenneirong = '';
				// 延迟关闭评论框，确保点击事件完成
				setTimeout(() => {
    			    this.pinglunzxianshi = 0;
    			}, 200);
			},
			denglu_jiance(){
				// 检查是否登录（通过Vuex状态判断）
				// 检查是否登录（通过Vuex状态判断）
  				const isLoggedIn = this.$store.state.memberuid && this.$store.state.keycode;
  				if (!isLoggedIn) {
  				  // 未登录，通过ref调用子组件的登录弹窗方法
  				  this.$refs.dToubu.dengluzhi();
  				  uni.showToast({
  				    title: '请先登录',
  				    icon: 'none'
  				  });
  				}
  				return isLoggedIn; // 返回登录状态    			    			    			    			    			    			    			    			
			},
			goumai(){
				// 先判断是否登录，如果没有登录，那么弹出 子组件中登录框
				// 检查是否登录（通过Vuex状态判断）
				if (!this.denglu_jiance()) return;
				// 已登录，执行购买逻辑
				console.log('人民币执行购买操作',this.uid_data.money);
				// 把 this.zhishi_data.jiage 和 this.uid_data.money 化成数字，在做比较
				var jiage = Number(this.zhishi_data.jiage);
				var money = Number(this.uid_data.money);
				if(jiage > money){
					// 购买
					uni.showToast({
					  title: '余额不足,请充值',
					  icon: 'none'
					});
					//弹出充值页面
					this.show = true;
					// 充值金额
					this.jine = this.zhishi_data.jiage;
					//打印
					console.log('充值金额',this.jine);
				} else {
					//弹出确认购买按钮
					uni.showModal({
					  title: '确认购买',
					  content: '支付' + this.zhishi_data.jiage + '元？',
					  success: (res) => {
					    if (res.confirm) {
					      console.log('用户点击了确认购买');
					      // 执行购买操作
					      this.postGoumai_api(this.zhishi_data.id);
					    } else if (res.cancel) {
					      console.log('用户点击了取消购买');
					      // 不执行任何操作
					    }
					  }
					});
				}
			},
			//购买接口
			postGoumai_api(id){
				//购买扣除费用
				const uid = this.$store.state.memberuid;
				const code = this.$store.state.keycode;
				
				var datas = "is_ajax=1&data[id]="+id;

				var post_data = postRequest(YingyongApi.postGoumai(uid,code,id),datas);
				var res;
				post_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						//成功
						uni.showToast({
						  title: '购买成功',
						  icon: 'success' //成功图标
						});
						// 更新数据
						this.getxiangqing_api(); //更新信息
						this.getUid_api(); //更新个人信息
					} else {
						uni.showToast({
						  title: res.data.msg,
						  icon: 'error' //失败图标
						});
					}
				})

			},
			handleLogout() {
 			  // 用户退出时关闭阅读界面
 			  this.yuedu = false;

 			  // 停止并销毁音频
 			  this.clearAllAudio();
 			},
			 denglu_fabu(){
				if(this.yidenglu == 0){
					this.denglu_xianshi = 1;
				} else {
					this.denglu_xianshi = 0;	
				}
				
				console.log('发布登录',this.denglu_xianshi);
				
			},
			// 更新判断是否登录
			handleUpdateDengluxianshi(value) {
			  this.denglu_xianshi = value;
			  console.log('关闭登录',this.denglu_xianshi);
			},
			// 信息
			getxiangqing_api(){
				// id
				const uid = this.$store.state.memberuid;
				const code = this.$store.state.keycode;
				// id ,cid 参数
				const data = {
					id: this.id,
				}
				var get_data = getRequest(YingyongApi.getyingyong_xiangqing(uid,code),data);

				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						// 转换时间戳为日期格式
						var zhishi_data = res.data? res.data.data[0] : [];
						this.zhishi_data = zhishi_data;
						this.dataLoaded = true;

					}
				})
			},
			// 帖子列表
			getTiezi_api(data,isLoadMore = false){
				if (!data) data = {};
				if (!data) data = {};
				if (!data.page) data.page = 1;
				//if (!data.categories) data.categories = 0;
				if (!data.search) data.search = '';
				data.categories  = this.id;
				const canshu = {
					shuxing:this.shuxing,
				}

				
				var get_data = getRequest(ZhishiApi.getTiezi_list(data),canshu);
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data? res.data.data : {};
						if (isLoadMore) {
        				  // 加载更多时追加数据
        				  this.tiezi_list = [...this.tiezi_list, ...list];
        				} else {
        				  // 非加载更多时替换数据
        				  this.tiezi_list = list;
        				}	
						this.noMoreData = list.length < this.pageSize;

					} else {
						uni.showToast({
							icon: 'none',
							title: '获取失败，请稍后重试'
						});
					}
					this.isLoading = false;
				}).catch(() => {
    			  this.isLoading = false;
    			  if (isLoadMore) {
    			    this.currentPage--; // 加载失败时回退页码
    			  }
    			});


			},
			// 下拉加载更多
			onReachBottom() {
  			  if (this.isLoading || this.noMoreData) return;
  			  this.isLoading = true;
  			  this.currentPage++;
			  // 获取当前激活的分类ID
    			const currentCategoryId = this.activeIndex.id >= 0 ? this.activeIndex.id : 0;
    			

  			  const data = {
  			    page: this.currentPage,
  			    categories: currentCategoryId
  			  };
			  console.log('分页',this.activeIndex.id);
  			  this.getTiezi_api(data, true); // 添加第二个参数表示是加载更多
  			},
			
			// 获取个人信息
			getUid_api(){
				const uid = this.$store.state.memberuid;
                const keycode = this.$store.state.keycode;
				//判断  uid 和 keycode 同时存在，才执行下一步
				if(!uid || !keycode) {
					
					return;
				}

				var get_data = getRequest(Api.getUID(uid,keycode));
				var res;	
				get_data.then(duixin_data => {
					res = duixin_data;	
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data ? res.data.data : {};
						this.uid_data = list;	
						// 判断是否还有更多数据
					}
				})

			},
			chuangyejin_post(id){
				if (!this.denglu_jiance()) return;
				// 已登录，执行购买逻辑
				console.log('执行购买操作');
				if(this.zhishi_data.chuangyejin > this.uid_data.score){
					// 购买
					uni.showToast({
					  title: '赞助金不足,请充值',
					  icon: 'none'
					});
					
					//打印
					//console.log('充值赞助金');
				} else {
				//弹出确定按钮
					uni.showModal({
						title: '提示',
						content: '确定要购买吗？',
						success: (res) => {
							if (res.confirm) {
								// 用户点击了确定按钮
								// 执行购买操作
								this.chuangyejin_goumai(id);
							} else if (res.cancel) {
								// 用户点击了取消按钮
								// 不执行任何操作
							}
						}
					});
				}
			},
			chuangyejin_goumai(id){
				// 购买
				const uid = this.$store.state.memberuid;
                const keycode = this.$store.state.keycode;
				//判断  uid 和 keycode 同时存在，才执行下一步
				if(!uid || !keycode) {
					uni.showToast({
					  title: '请先登录',
					  icon: 'none'
					});
					return;
				}
				// 购买
				var datas = "is_ajax=1&data[id]="+id;
				var post_data = postRequest(YingyongApi.chuangyejin_goumai(uid,keycode,id),datas);
				var res;
				post_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						uni.showToast({
						  title: '购买成功',
						  icon: 'success'
						});
						// 刷新数据
						this.getxiangqing_api();
						// 刷新数据
						this.getUid_api();

						
					} else {
						uni.showToast({
						  title: '购买失败',
						  icon: 'none'
						});
					}
				})
			}



		}
	}
</script>

<style scoped lang="scss">

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		/*justify-content: center;*/
		background-color: #f3f3f3;
		/*height: calc(100vh - 0px);*/ /* 添加全屏 */
		box-sizing: border-box;
		overflow-x: hidden;

	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	/* 屏幕宽度大于786px时隐藏uni-page-head */
    @media (min-width: 786px) {
        uni-page-head {
            display: none !important;
            opacity: 0 !important;
            height: 0 !important;
            visibility: hidden !important;
        }
    }
	/* 添加在style部分 */
	.d-daohang-zuo {
    position: fixed;
    left: 0;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #f5f5f5;
    z-index: 100;
	box-shadow: 2px 0 5px rgba(177, 177, 177, 0.1);
  }
  
  .d-daohang-you {
    position: fixed;
    left: 180rpx;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #fff;
    z-index: 999;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  }
  .d-erji-item {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 20rpx;
   /* border-bottom: 1px solid #f0f0f0;*/
  }
  
  .d-erji-item:active {
    background: #f5f5f5;
  }
  @mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
        
	}
    ::v-deep .uv-navbar {
      border-radius: 20rpx;
    }
    .you-guding {
        
        position: fixed;
        
        top: 60px; /* 根据头部高度调整 */
        /*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
        transition: all 0.3s ease;
        
        

    }
	/*@font-face {
		font-family: 'icon';
		src: url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.woff2?t=1749392833400') format('woff2'), url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.woff?t=1749392833400') format('woff'),
			url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.ttf?t=1749392833400') format('truetype');
	}*/

	.audio-control-wrapper {
		margin-top: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-family: 'icon' !important;
	}

	.audio-control {
		font-size: 62rpx;
		line-height: 1;
		padding: 16rpx;
		color: #12d1b1;
		font-size: 80rpx;
	}

	.audio-control-prev {
		transform: rotate(180deg);
	}

	.audio-control-switch {
		font-size: 80rpx;
		margin: 0 100rpx;
	}
	.d-gundongtiao {
		::-webkit-scrollbar {
			width: 1px;
		}
		::-webkit-scrollbar-thumb {
			background-color: #ffffff00;
		}
	}
	.uv-content {
        padding: 24rpx;
        font-size: 40rpx;
        color: #000000;
        line-height: 1.8;
    }


	
</style>
